package com.quikin.web.controller.json.aa;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.quikin.persistence.jpa.entity.aa.UserProfile;
import com.quikin.persistence.jpa.service.aa.AAEntryService;
import com.quikin.persistence.jpa.util.QuikinPLException;
import com.quikin.web.controller.json.JsonController;
import com.quikin.web.controller.util.ResponseHeader;
import com.von.platform.orm.TransactionException;


@Controller
public class AAService extends JsonController {

    private static final Logger logger = Logger.getLogger(AAService.class);
    
    @RequestMapping("json/login")
    public ModelAndView loginIn(String loginId, String password, HttpServletRequest req, Locale locale) throws QuikinPLException, TransactionException {
        ModelAndView mav = new ModelAndView();
        mav.setViewName("json/aaa/login");
        try {
            UserProfile user = AAEntryService.getInstance().login(loginId, password);
            mav.addObject("user", user);
            createSuccessHeaderInfo(mav);
            logger.debug("User login Success");
        } catch (QuikinPLException e) {
            logger.error("Login Error:"+e.getMessage(),e);
            createPageInfo(ResponseHeader.FAIL.name(),e.getMessage(),e.getLocalizedMessage(locale),mav);
        } 
        return mav;
    }

    @RequestMapping("json/test")
    public ModelAndView loginIn(HttpServletRequest req, Locale locale) { 
        ModelAndView mav = new ModelAndView();
        mav.setViewName("json/aaa/login");
        createSuccessHeaderInfo(mav);
        return mav; 
    }

}
